@extends("admin.base")
@section("contents")
    <div class="row">
        <div class="col-lg-6 m-auto">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-primary table-striped mb-0">


                            <tr>
                                <th>id</th>
                                <th>type_ch</th>
                                <th>type_uy</th>
                                <th>order</th>
                                <th>created_at</th>
                                <th>updated_at</th>
                                <th>操作</th>
                            </tr>
                            @foreach($langs as $lang)
                                <tr>
                                    <th>{{$lang->id}}</th>
                                    <th>{{$lang->language_ch}}</th>
                                    <th>{{$lang->language_uy}}</th>
                                    <th>{{$lang->order}}</th>
                                    <th>{{$lang->created_at}}</th>
                                    <th>{{$lang->updated_at}}</th>
                                    <th>
                                        <a href=updatelang?id={{$lang->id}}">
                                            <button class="btn btn-outline-primary">修改</button>
                                        </a>
                                        <button onclick="deletelang({{$lang->id}})" class="btn btn-outline-danger">删除
                                        </button>
                                    </th>
                                </tr>
                            @endforeach
                        </table>
                    </div>

                </div>
            </div>
        </div>
        @endsection


        @section("scripts")
            <script>
                function deletelang(id) {
                    swal({
                        title: "请确认操作",
                        text: "数据被删除后无法恢复，请确认",
                        icon: "warning",
                        buttons: ["取消", "删除"],
                    }).then((willDelete => {
                        if (willDelete) {
                            $.ajax({
                                url: "deletelang",
                                type: "GET",
                                dataType: "json",
                                headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'},
                                async: true,
                                data: {"id": id},
                                success: function (req) {
                                    if (req.err == 0) {
                                        swal({
                                            title: "操作成功",
                                            text: "记录已删除",
                                            icon: "success",
                                            button: "知道了",
                                        })
                                        setTimeout(function () {
                                            location.reload();
                                        }, 1000)
                                    }
                                }
                            })
                        }
                    }));
                }
            </script>

@endsection
